package edu.sctu.zcy.month201506.day20150601;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * Created by user24 on 2015/6/5.
 */
public class DateUtil {

    private static DateUtil dateUtil = null;

    public  static DateUtil getDateUtil(){

        if(dateUtil == null){

            dateUtil = new DateUtil();
        }
        return dateUtil;
    }

    public void getTime(Calendar calendar1){

      Calendar calendar = Calendar.getInstance();

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        System.out.println("现在"+simpleDateFormat.format(calendar.getTime()));
        long now =  (calendar.getTimeInMillis()/1000);

        System.out.println("比较" + simpleDateFormat.format(calendar1.getTime()));
        long previous =(calendar1.getTimeInMillis()/1000);

        long timeDifference = now - previous;

        System.out.println("时间戳差"+timeDifference);

        int minute = (int) (timeDifference/60);
        int hour = (int) (timeDifference/60/60);
        int day = hour/24;

        System.out.println("时间差："+day+"天"+hour%24+"时"+(minute-hour*60)+"分前");

    }
}
